#include "shmem.h"
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <stdio.h>

#define SHM_ID  12345

int main(int argc, char const *argv[])
{
	int count =0;
	int shm_id;
	S_SHM_INFO* shm_info;
	char buffer[1204] = "[0]";
	shm_id = shmget((key_t)SHM_ID,sizeof(S_SHM_INFO),0666|IPC_CREAT);
	if(shm_id == -1)
	{
		printf("shmget failed!!!\n");
		return -1;
	}
	void* add = shmat(shm_id,0,0);
	if(add == (void *)-1){
		printf("read shm failed\n");
		return -1;
	}
	shm_info = (struct S_SHM_INFO*)add;
	while(true){
		if (shm_info->Wflag == 0)
		{
			sprintf(buffer,"%d",count);  
        	//fgets(buffer+3, 1000, stdin);  
        	strncpy(shm_info->text, buffer, 1024);  
        	shm_info->Wflag = 1;
        	count ++;
		}else{
			sleep(1);
		}
	}
	return 0;
}